﻿using System;
using System.Collections.Generic;
using System.IO;
using CSJ2K.Util.IO;

namespace CSJ2K.Jpc.Segments
{
    /// <summary>Packet length, tile-part header (PLT)</summary>
    /// <comment>
    /// Function: A list of packet lengths in the tile-part. 
    /// Usage: Tile-part headers. There may be multiple PLT marker segments per tile. Both 
    ///      the PLM and PLT marker segments are optional and can be used together or 
    ///      separately. Shall appear in any tile-part header before the packets whose 
    ///      lengths are described herein. 
    /// Length: Variable depending on the number of packets in each tile-part
    /// </comment>
    public class PLT : Segment
    {
        /// <summary>Index of this marker segment relative to all other PLT marker segments present in the current header.</summary>
        public byte Z;       

        /// <summary>Length of the ith packet.</summary>
        public byte[] I;

        public PLT(Stream source)
            : this(source, (Markers)StreamUtil.ReadBUInt16(source)) { }
        public PLT(Stream source, Markers marker)
            : base(source, marker, true)
        {
            if (marker != Markers.PLT) throw (new ApplicationException("Attempting to create segment of the wrong type."));

            Z = StreamUtil.ReadOctet(source);
            I = StreamUtil.ReadBytes(source, Length - 3);
        }
    }
}
